package com.zhl.media.app.app;

import android.content.Context;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Interceptor;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.template.IInterceptor;
import com.alibaba.android.arouter.launcher.ARouter;
import com.zhl.media.commonsdk.core.RouterHub;
import com.zhl.media.commonsdk.data.UserUtil;

@Interceptor(priority = 8, name = "RouterInterceptor")
public class RouterInterceptor implements IInterceptor {
    private Context mContext;
    @Override
    public void process(Postcard postcard, InterceptorCallback callback) {
        String path = postcard.getPath();
        boolean isLogin = UserUtil.getLoginStatus();
        if (isLogin) {
            callback.onContinue(postcard);
        }else {
            switch (path){
                case RouterHub.APP_SPLASHACTIVITY:
                case RouterHub.LOGIN_LOGINACTIVITY:
                    callback.onContinue(postcard);
                    break;
                default:
                    ARouter.getInstance().build(RouterHub.LOGIN_LOGINACTIVITY).navigation(mContext);
                    break;

            }
        }
    }
    @Override
    public void init(Context context) {
        mContext = context;
    }
}
